using UnityEngine;
using UnityEngine.UI;

public class TowerController : MonoBehaviour
{
	public float towerHP = 100;
	
	// 满血量
	public float fullHP = 100;
	public bool towerIsDestroyed = false;
	public GameMain gameMain;
	public GameObject blood;
	private Slider bloodSlider;
	
	
 	void Start()
	{
		bloodSlider = blood.GetComponent<Slider>();
	}
 
 	void Update()
 	{
		bloodSlider.value = towerHP / fullHP;
 	}

	public void towerBeAttacked(float attackValue)
	{
		towerHP -= attackValue;
		checkTowerDestroyed();
	}

	void checkTowerDestroyed()
	{
		if (GameStateManager.GameState == GameState.Playing)
		{
			if (towerHP <= 0)
			{
				towerDamage();
			}
		}
	}

	// 获取塔血量
	public float getTowerHP()
	{
		return towerHP;
	}

	// 塔坏掉
	void towerDamage()
	{
		towerIsDestroyed = true;
		gameMain.overGame();
	}

	// 塔重生
	public void towerRebirth()
	{
		towerHP = fullHP;
		towerIsDestroyed = false;
	}


	public void setBloodVisble(bool visible)
	{
		blood.SetActive(visible);
	}
 	
 }